#ifndef MAINWIDGET_H
#define MAINWIDGET_H

#include <QWidget>
#include <QLineEdit>

class QPushButton;
class QLabel;
class MessageShowArea;
class MessageEditArea;
class SessionFriendArea;


QT_BEGIN_NAMESPACE
namespace Ui {
class MainWidget;
}
QT_END_NAMESPACE

class MainWidget : public QWidget
{
    Q_OBJECT
    inline static const QString btnBaseStyle =
        "QPushButton { border:none; background:transparent; image:url(%1);}";
public:
    ~MainWidget();
    static MainWidget* getInstance();

private:
    MainWidget(QWidget *parent = nullptr);
    static MainWidget* instance;

private:
    Ui::MainWidget* ui;
    QWidget* windowLeft;
    QWidget* windowMid;
    QWidget* windowRight;

    // 用户头像
    QPushButton* userAvatar;

    // 用户搜素框 & 添加按钮
    QLineEdit* searchEdit;
    QPushButton* addFriendBtn;

    // tab 按钮
    QPushButton* sessionTabBtn;
    QPushButton* friendTabBtn;
    QPushButton* applyTabBtn;

    // 会话标题
    QLabel* sessionTitle;

    // 会话详情按钮
    QPushButton* sessionDetailBtn;

    enum ActiveTab {
        SESSION_LIST,
        FRIEND_LIST,
        APPLY_LIST
    };

    ActiveTab activeTab = ActiveTab::SESSION_LIST;

    MessageShowArea* messageShowArea;
    MessageEditArea* messageEditArea;
    SessionFriendArea* sessionFriendArea;

private:
    void initMainWindow();
    void initWindowLeft();
    void initWindowMid();
    void initWindowRight();

    void initSingalSlot();
    void switchTabToSession();
    void switchTabToFriend();
    void switchTabToApply();

    void loadSessionList();
    void loadFriendList();
    void loadApplyList();

    void updateSessionList();
    void updateFriendList();
    void updateApplyList();
    void updateRecentMessageList(const QString& chatSessionId);

public:
    void loadRecentMessages(const QString& chatSessionId);

    void switchToSession(const QString& userId);

    MessageShowArea* getMessageShowArea();
};
#endif // MAINWIDGET_H
